<template>
  <div class="register">
    <div class="card">
      <el-form
        :model="ruleForm"
        status-icon
        :rules="rules"
        ref="ruleForm"
        label-width="122px"
        class="demo-ruleForm myfrom"
        run
      >
        <h1 style="margin-bottom: 40px;">升级为家政公司</h1>

        <el-form-item label="家政公司账号：" prop="homeaccount">
          <el-input type="text" clearable v-model="ruleForm.homeaccount" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item label="法人代表：" prop="legalPerson">
          <label slot="label">法&nbsp;&nbsp;人&nbsp;&nbsp;代&nbsp;&nbsp;表：</label>
          <el-input type="text" clearable v-model="ruleForm.legalPerson" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码：" prop="password">
          <label
            slot="label"
          >密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码:</label>
          <el-input type="password" show-password v-model="ruleForm.password" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item label="确认密码：" prop="checkPass">
          <label slot="label">确&nbsp;&nbsp;认&nbsp;&nbsp;密&nbsp;&nbsp;码：</label>
          <el-input type="password" show-password v-model="ruleForm.checkPass" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item label=" 法人电话：">
          <label slot="label">法&nbsp;&nbsp;人&nbsp;&nbsp;电&nbsp;&nbsp;话：</label>
          <el-input type="tel" v-model="ruleForm.phone"></el-input>
        </el-form-item>

        <el-form-item label="公司地址：">
          <label slot="label">公&nbsp;&nbsp;司&nbsp;&nbsp;地&nbsp;&nbsp;址:</label>
          <el-input type="text" v-model="ruleForm.address"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button class="mar_del" type="primary" @click="submitForm('ruleForm')">升级</el-button>

          <el-button class="mar_del_back" @click="backForm()">返回</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    var validatePass2 = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请再次输入密码'))
      } else if (value !== this.ruleForm.password) {
        callback(new Error('两次输入密码不一致!'))
      } else {
        callback()
      }
    }
    return {
      captchaImg: '',
      token: '',
      ruleForm: {
        homeaccount: '',
        legalPerson: '',
        password: '',
        checkPass: '',
        phone: '',
        code: '',
        address: '',
      },
      rules: {
        homeaccount: [
          { required: true, message: '请输入家政公司账号名', trigger: 'blur' },

          {
            min: 3,
            max: 10,
            message: '长度在 3 到 10 个字符',
            trigger: 'blur',
          },
        ],
        legalPerson: [
          { required: true, message: '请输入法人代表', trigger: 'blur' },
          {
            min: 2,
            max: 10,
            message: '长度在 3 到 10 个字符',
            trigger: 'blur',
          },
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          {
            min: 3,
            max: 10,
            message: '长度在 3 到 10 个字符',
            trigger: 'blur',
          },
        ],
        checkPass: [
          { required: true, validator: validatePass2, trigger: 'blur' },
        ],
        code: [
          { required: true, message: '请输入验证码', trigger: 'blur' },
          { min: 5, max: 5, message: '长度为 5 个字符', trigger: 'blur' },
        ],
      },
    }
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate(async (valid) => {
        if (valid) {
          const { data } = await this.$http.post('/sys/user/upgrade/register', {
            id: this.$store.getters.getUserInfo.id,
            username: this.ruleForm.homeaccount,
            password: this.ruleForm.password,
            legalPerson: this.ruleForm.legalPerson,
            phone: this.ruleForm.phone,
            address: this.ruleForm.address,
          })
          if (data.code != 200) {
            this.$refs[formName].resetFields()
            this.$message.error(data.msg)
          } else {
            this.$refs[formName].resetFields()
            this.$message.success(data.msg)

            this.$router.go(-1)
          }
        }
      })
    },

    backForm() {
      this.$router.go(-1)
    },
    suer() {
      if (this.ruleForm.checkPass != this.ruleForm.password) {
        this.$message.error('两次密码不同！！')
      }
    },
  },
}
</script>

<style lang="less" scoped>
.register {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100vw;
  height: 120vh;

  //  background: url("~@/assets/imags/login/login.jpg") center center no-repeat;

  background-size: cover;
}
.card {
  width: 28rem;
  padding: 20px;
  background: rgba(255, 255, 255, 0.35);
  border: 0.5px solid rgba(127, 255, 212, 0.3);
}
.el-form {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
}
.el-message {
  top: 200px !important;
}
h1 {
  // letter-spacing: 6px;
  font-size: 18px;
  margin-top: 8px;
  color: #888888;
}
h2 {
  margin-top: 5px;
}
.btn-outline-primary {
  color: #fff !important;
}
.el-input--suffix {
  width: 220px !important;
}
.el-form-item {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  margin-bottom: 18px;
}
.sexSelect {
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  margin-left: 20px;
}
.el-form-item__content {
  display: flex !important;
}
.sex_style {
  margin-right: 130px !important;
  // margin-bottom: 22px;
}
.sex_radio {
  position: relative;
  right: 106px;
}
.radio__label {
  font-size: 17px;
  padding-left: 10px;
}
</style>
